package com.design.pattern.structure.flyweight.general;

import java.util.HashMap;
import java.util.Map;

/**
 * 享元工厂
 */
public class FlyweightFactory {
    //缓存池
    private static Map<String, IFlyweight> pool = new HashMap<>();
    IFlyweight flyweight;
    //因为内部状态具备不变形，因此作为缓存的键
    public static IFlyweight getFlyweight(String op){
        if(!pool.containsKey(op)) {
            IFlyweight flyweight = new ConcreteFlyweight(op);
            pool.put(op, flyweight);
        }
        return pool.get(op);
    }
}
